const koa= require('koa');
const app = new koa()
const router = require('./router')
const middleware = require('./middlewere')
const {
    connect,
    close
} = require('./model/conn')


middleware(app);

// router(app);
// koa-compose 多个中间件组合单一中间件
// app.use( compose([middleFunc1,middleFunc2,middleFunc3，...]))
app.use(async (context, next) => {
    await connect()
    await next()
    await close()
})

app.use(router.routes()).use(router.allowedMethods());

app.listen(3001,()=>{
    console.log('server run at 127.0.0.1:3001')
})